package be.castanea.client.delegate;

import be.castanea.client.CastaneaClient;
import be.castanea.client.model.Self;
import be.castanea.client.model.World;
import be.castanea.common.JoinEvent;
import be.castanea.common.JoinReplyEvent;
import be.castanea.common.MovementChangedEvent;

/**
 * Castanea
 * 2009
 * @author Geert van Leemputten, Steven Rymenans, Bart Van Hooydonck
 */
public class ServerDelegate {

    public static void dispatchJoin() {
        Self self = Self.getInstance();
        String originator = self.getName();
        String recipient = World.getInstance().getName();
        float[] location = new float[3];
        self.getWorldTranslation().toArray(location);
        float[] rotation = new float[3];
        self.getWorldRotation().toAngles(rotation);
        int[] movement = self.getMovement().toArray();
        CastaneaClient.send(new JoinEvent(originator, recipient, location, rotation, movement));
    }

    public static void dispatchJoinReply(String recipient) {
        Self self = Self.getInstance();
        String originator = self.getName();
        float[] location = new float[3];
        self.getWorldTranslation().toArray(location);
        float[] rotation = new float[3];
        self.getWorldRotation().toAngles(rotation);
        int[] movement = self.getMovement().toArray();
        CastaneaClient.send(new JoinReplyEvent(originator, recipient, location, rotation, movement));
    }

    public static void dispatchMovementChange() {
        Self self = Self.getInstance();
        String originator = self.getName();
        String recipient = World.getInstance().getName();
        float[] location = new float[3];
        self.getWorldTranslation().toArray(location);
        float[] rotation = new float[3];
        self.getWorldRotation().toAngles(rotation);
        int[] movement = self.getMovement().toArray();
        CastaneaClient.send(new MovementChangedEvent(originator, recipient, location, rotation, movement));
    }
}
